const app = getApp()
var t = getApp(), a = t.requirejs("core"), e = t.requirejs("wxParse/wxParse"), i = t.requirejs("biz/diypage"), s = t.requirejs("biz/diyform"), n = t.requirejs("biz/goodspicker"), o = (t.requirejs("foxui"), 
t.requirejs("jquery"));
Page({
  data: {
    article:'',
    id:'',//id
    isClick:true,
    orginelist:[],//原图
    limitImg:9,
    mode:1,// 文章 2评论
    typeList:[],
    typeIndex:0,
    author:'',//被投诉的名称
  },
  typeC(e){
    this.setData({
      typeIndex:e.currentTarget.dataset.index,
    })
  },
  itemDel(e){
    let orginelist=this.data.orginelist;
    orginelist.splice(e.currentTarget.dataset.index,1);
    this.setData({
      orginelist:orginelist
    })
  },
  addPic(){
    let that=this;
    let orginelist=this.data.orginelist;
    a.upload(function(e) {
      orginelist.push(e.url)
      that.setData({
        orginelist:orginelist
      })
    })
  },
  articleC(e){
    this.setData({
      article:e.detail.value
    })
  },
  //保存
  send(){
    if(!this.data.isClick)return
    this.setData({
      isClick:false
    });
    
    let t=setTimeout(()=>{
      clearTimeout(t)
      this.setData({
        isClick:true
      });
    },3000);
    let that=this;
    let type=this.data.typeList[this.data.typeIndex].id;
    a.post("sns/board/complain", {
      id:that.data.id,
      type:type,
      content:that.data.article,
      images:that.data.orginelist,
    }, function(res) {
      if(res.error==-2){
        wx.showToast({
          title:res.message,
          icon:'none'
        })
        return
      }
      wx.showToast({
        title:'投诉成功',
        icon:'none'
      });
      that.setData({
        article:'',
        orginelist:[],
      })
    })
  },
  onLoad: function (options) {
    let that=this;
    wx.getSystemInfo({
      success: (result) => {
        that.setData({
          windowWidth:result.windowWidth
        })
      },
    })
    if(options.mode){
      this.setData({
        mode:options.mode
      })
    }
    if(options.id){
      this.setData({
        id:options.id
      })
    }
    if(options.author){
      this.setData({
        author:options.author
      })
    }
    
    let pages = getCurrentPages();
    let prePage = pages[pages.length - 2];
    let typeList=prePage.data.info.catelist;
    typeList.push({
      id:-1,
      name:"其它"
    });
    this.setData({
      typeList:typeList
    })
  },
  onReady: function () {
    
  },
  onShow: function () {
  },
  onHide: function () {

  },
  onUnload: function () {

  },
  onPullDownRefresh: function () {

  },
  onReachBottom: function () {

  }
})